﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using DAL;

namespace _3tiers
{
    public partial class Form4ThemMon : Form
    {
        public Form4ThemMon()
        {
            InitializeComponent();
        }

        private void Form4ThemMon_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'quanLyLichDayDataSet6.tblBoMon' table. You can move, or remove it, as needed.
            this.tblBoMonTableAdapter.Fill(this.quanLyLichDayDataSet6.tblBoMon);
            try
            {
                //string sql = "select * from tblBoMon";
                string sql = "select TenMon,TenBoMon,SoTinChi from tblBoMon bm,tblMon m where bm.IDBoMon=m.IDBoMon";
                dataGridView1.DataSource = business.ShowData(sql);
                dataGridView1.Show();

            }
            catch { } 

        }

        private void cbBoMon_SelectedIndexChanged(object sender, EventArgs e)
        {
            //string id;
            //id = cbBoMon.SelectedValue.ToString();
            //MessageBox.Show(id);
        }

        private void btreset_Click(object sender, EventArgs e)
        {
            tbTinChi.Text = "";
            tbTenMon.Text = "";
        }
        DataAccess ac = new DataAccess();
        BLL.BLL business = new BLL.BLL();
        
        private void btThem_Click(object sender, EventArgs e)
        {
            try
            {
                string IDBoMon;
                IDBoMon = cbBoMon.SelectedValue.ToString();
                string sql = "insert into tblMon values('b','" + IDBoMon + "','" + tbTenMon.Text + "','" + tbTinChi.Text + "')";
                business.Insert(sql);
                lbThongBao.Text = "Thêm môn thành công.";
            }
            catch { lbThongBao.Text = "Thêm môn thất bại"; }
            Form4ThemMon_Load(sender, e);
            try
            {
                //string sql = "select * from tblBoMon";
                string sql = "select TenMon,TenBoMon,SoTinChi from tblBoMon bm,tblMon m where bm.IDBoMon=m.IDBoMon";
                dataGridView1.DataSource = business.ShowData(sql);
                dataGridView1.Show();
                
            }
            catch { } 
        }
    }
}
